<template>
	<div class="add"><el-button type="primary" @click="add">添加</el-button></div>
	<el-dialog
	    v-model="dialogVisible_add"
	    title="Tips"
	    width="500"
	  >
	    <el-input type="text" v-model="name" placeholder="请输入添加的权限名"></el-input>
	    <template #footer>
	      <div class="dialog-footer">
	        <el-button @click="dialogVisible_add = false">Cancel</el-button>
	        <el-button type="primary" @click="addSubmit">
	          Confirm
	        </el-button>
	      </div>
	    </template>
	  </el-dialog>
	  <el-dialog
	      v-model="dialogVisible_update"
	      title="Tips"
	      width="500"
	    >
	      <el-input type="text" v-model="name" placeholder="请输入更改的权限名"></el-input>
	      <template #footer>
	        <div class="dialog-footer">
	          <el-button @click="dialogVisible_update = false">Cancel</el-button>
	          <el-button type="primary" @click="updateSubmit">
	            Confirm
	          </el-button>
	        </div>
	      </template>
	    </el-dialog>
	<el-dialog
	  v-model="dialogVisible_del"
	  title="Tips"
	  width="500"
	>
	  确认要删除 {{delName}} 吗？
	  <template #footer>
	    <div class="dialog-footer">
	      <el-button @click="dialogVisible_del = false">Cancel</el-button>
	      <el-button type="primary" @click="delSubmit">
	        Confirm
	      </el-button>
	    </div>
	  </template>
	</el-dialog>
	<el-table :data="tableData" style="width: 1200px;">
	  <el-table-column prop="name" label="权限名" width="180" />
	  <el-table-column prop="createTime" label="创建时间" />
	  <el-table-column prop="updateTime" label="更新时间" />
	  <el-table-column>
	  	<template #header>操作</template>
	  	<template #default="scope">
	  	  <el-button type="warning" @click="update(scope.row.id,scope.row.name)">编辑</el-button>
	  	  <el-button type="danger" @click="del(scope.row.id,scope.row.name)">删除</el-button>
	  	</template>
	  </el-table-column>
	</el-table>
</template>

<script setup>
	import {ref} from 'vue'
	const tableData = ref([])
	import {http} from "../components/http.js"
	function query(){
		http({url:"/queryPermission",method:"get"}).then(res=>{
			tableData.value = res.data.data
		})
	}
	query()
	const dialogVisible_add = ref(false)
	const dialogVisible_update = ref(false)
	const dialogVisible_del = ref(false)
	const name = ref("")
	function add(){
			dialogVisible_add.value = true
			name.value = ""
			// http.get("/user/queryPage?pageSize=0&pageNum=0").then(res=>{
			// 	options.value = res.data.data.list
			// })
		}
	function addSubmit(){
		http({url:"/addPermission",method:"post",data:{name:name.value}}).then(res=>{
			dialogVisible_add.value = false
			query()
		})
	}
	const updateId = ref(undefined)
	function update(id,name){
		dialogVisible_update.value = true
		updateId.value = id
	}
	function updateSubmit(){
		http({url:"/updatePermission",method:"post",data:{id:updateId.value,name:name.value}}).then(res=>{
			dialogVisible_update.value = false
			query()
		})
	}
	const delName = ref("")
	const delId = ref(undefined)
	function del(id,name){
			delId.value = id
			delName.value = name
			dialogVisible_del.value = true
		}
	function delSubmit(){
		http({url:"/delPermission?id="+delId.value,method:"get"}).then(res=>{
				dialogVisible_del.value = false
				query()
		})
	} 
</script>

<style>
</style>